package
{
	import capricornus.components.scrollbar.ScrollPolicy;
	import capricornus.components.tilelist.TileList;
	
	import flash.display.GradientType;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	[SWF(backgroundColor="#333333")]
	public class ListTest extends Sprite
	{
		private var _list:TileList;
		private var _s:Sprite;
		private var _txt:TextField;
		
		public function ListTest()
		{
			super();
			init();
		}
		
		private function init():void
		{
			_list = new TileList(1);
			_list.setSize( 100, 100 );
			_list.setLocation( 100, 100 );
			_list.horizonalScrollPolicy = ScrollPolicy.AUTO;
			addChild( _list );
			
			_s = new Sprite();
			_s.graphics.beginFill( 0xff0000 );
			_s.graphics.drawRect( 0, 0, 40, 40 );
			addChild( _s );
			
			_txt = new TextField();
			_txt.width = 100;
			_txt.height = 22;
			_txt.border = true;
			_txt.x = 50;
			addChild( _txt );
			
			_s.addEventListener( MouseEvent.MOUSE_DOWN, onMDown );
		}
		
		private function onMDown( e:MouseEvent ):void
		{
			var item:Sprite = new Sprite();
			item.graphics.lineStyle( 1, 0xffffff );
			item.graphics.beginGradientFill( GradientType.RADIAL, [0,0xff0000], [1,1], [0,255] );
			item.graphics.drawRect( 0, 0, 150*Math.random(), 150*Math.random() );
			_list.removeAllItem();
			_list.addItem( item );
			
			_txt.text = int(item.width) + ", " + int(item.height);
		}
	}
}